using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterSpawner : MonoBehaviour
{
    public GameObject[] lowDistortionMonsters; // 低失真度的怪物预制体数组 (0-100)
    public GameObject[] mediumDistortionMonsters; // 中等失真度的怪物预制体数组 (100-300)
    public GameObject[] highDistortionMonsters; // 高失真度的怪物预制体数组 (300+)

    public Transform[] wave1SpawnPoints; // 第一波刷怪点数组
    public Transform[] wave2SpawnPoints; // 第二波刷怪点数组

    public GameObject warningPrefab; // 警告标志预制体
    public float warningDuration = 2f; // 警告标志显示时间
    public float waveInterval = 10f; // 波次之间的时间间隔

    private Player player; // 玩家当前的失真度

    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
        StartCoroutine(SpawnWaves());
    }

    IEnumerator SpawnWaves()
    {
        // 生成第一波怪物
        yield return StartCoroutine(SpawnMonstersWithWarning(wave1SpawnPoints));
        yield return new WaitForSeconds(waveInterval); // 等待指定时间间隔

        // 生成第二波怪物
        yield return StartCoroutine(SpawnMonstersWithWarning(wave2SpawnPoints));
    }

    IEnumerator SpawnMonstersWithWarning(Transform[] spawnPoints)
    {
        // 显示警告标志
        foreach (Transform spawnPoint in spawnPoints)
        {
            Instantiate(warningPrefab, spawnPoint.position, Quaternion.identity);
        }

        // 等待警告标志显示时间
        yield return new WaitForSeconds(warningDuration);

        // 生成怪物
        SpawnMonsters(spawnPoints);
    }

    void SpawnMonsters(Transform[] spawnPoints)
    {
        foreach (Transform spawnPoint in spawnPoints)
        {
            // 根据玩家的失真度选择怪物预制体数组
            GameObject[] monstersToSpawn;

            if (player.stats.distortionLevel >= 300)
            {
                monstersToSpawn = highDistortionMonsters;
            }
            else if (player.stats.distortionLevel >= 100)
            {
                monstersToSpawn = mediumDistortionMonsters;
            }
            else
            {
                monstersToSpawn = lowDistortionMonsters;
            }

            // 随机选择一个怪物预制体
            GameObject monsterPrefab = monstersToSpawn[Random.Range(0, monstersToSpawn.Length)];
            // 在刷怪点生成怪物
            Instantiate(monsterPrefab, spawnPoint.position, spawnPoint.rotation);
        }
    }

    // 假设有一个方法来更新玩家的失真度
}
